using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GiaoVienDAO
/// </summary>
public class GiaoVienDAO:DataProvider
{
	public GiaoVienDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public ArrayList LayMang_GiaoVien()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_GiaoVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                GiaoVienDTO obj = new GiaoVienDTO();
                obj.MaGiaoVien = dr.GetString(0);
                obj.TenGiaoVien = dr.GetString(1);
                obj.ChucDanh = dr.GetString(2);
                obj.HocHam = dr.GetString(3);
                obj.HocVi = dr.GetString(4);
                obj.Email = dr.GetString(5);
                obj.DienThoai = dr.GetString(6);
                obj.HinhAnh = dr.GetString(7);
                obj.HuongNghienCuu = dr.GetString(8);
                obj.NoiCongTac = dr.GetString(9);
                obj.MaBoMon = dr.GetInt32(10);

                arr.Add(obj);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return arr;

    }
    public void insert(GiaoVienDTO obj)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_GiaoVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@TenGiaoVien", SqlDbType.NVarChar);
            cmd.Parameters["@TenGiaoVien"].Value = obj.TenGiaoVien.ToString();
            cmd.Parameters["@TenGiaoVien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ChucDanh", SqlDbType.NVarChar);
            cmd.Parameters["@ChucDanh"].Value = obj.ChucDanh.ToString();
            cmd.Parameters["@ChucDanh"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HocHam", SqlDbType.NVarChar);
            cmd.Parameters["@HocHam"].Value = obj.HocHam.ToString();
            cmd.Parameters["@HocHam"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HocVi", SqlDbType.NVarChar);
            cmd.Parameters["@HocVi"].Value = obj.HocVi.ToString();
            cmd.Parameters["@HocVi"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@Email", SqlDbType.NVarChar);
            cmd.Parameters["@Email"].Value = obj.Email.ToString();
            cmd.Parameters["@Email"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar);
            cmd.Parameters["@DienThoai"].Value = obj.DienThoai.ToString();
            cmd.Parameters["@DienThoai"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HinhAnh", SqlDbType.NVarChar);
            cmd.Parameters["@HinhAnh"].Value = obj.HinhAnh.ToString();
            cmd.Parameters["@HinhAnh"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HuongNghienCuu", SqlDbType.NVarChar);
            cmd.Parameters["@HuongNghienCuu"].Value = obj.HuongNghienCuu.ToString();
            cmd.Parameters["@HuongNghienCuu"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@NoiCongTac", SqlDbType.NVarChar);
            cmd.Parameters["@NoiCongTac"].Value = obj.NoiCongTac.ToString();
            cmd.Parameters["@NoiCongTac"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@MaBoMon", SqlDbType.Int);
            cmd.Parameters["@MaBoMon"].Value = obj.MaBoMon;
            cmd.Parameters["@MaBoMon"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void delete(string ma)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Delete_GiaoVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaGiaoVien", SqlDbType.VarChar);
            cmd.Parameters["@MaGiaoVien"].Value = ma;
            cmd.Parameters["@MaGiaoVien"].Direction = ParameterDirection.Input;
            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void update(GiaoVienDTO obj)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_GiaoVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaGiaoVien", SqlDbType.VarChar);
            cmd.Parameters["@MaGiaoVien"].Value = obj.MaGiaoVien.ToString();
            cmd.Parameters["@MaGiaoVien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@TenGiaoVien", SqlDbType.NVarChar);
            cmd.Parameters["@TenGiaoVien"].Value = obj.TenGiaoVien.ToString();
            cmd.Parameters["@TenGiaoVien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ChucDanh", SqlDbType.NVarChar);
            cmd.Parameters["@ChucDanh"].Value = obj.ChucDanh.ToString();
            cmd.Parameters["@ChucDanh"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HocHam", SqlDbType.NVarChar);
            cmd.Parameters["@HocHam"].Value = obj.HocHam.ToString();
            cmd.Parameters["@HocHam"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HocVi", SqlDbType.NVarChar);
            cmd.Parameters["@HocVi"].Value = obj.HocVi.ToString();
            cmd.Parameters["@HocVi"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@Email", SqlDbType.NVarChar);
            cmd.Parameters["@Email"].Value = obj.Email.ToString();
            cmd.Parameters["@Email"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@DienThoai", SqlDbType.NVarChar);
            cmd.Parameters["@DienThoai"].Value = obj.DienThoai.ToString();
            cmd.Parameters["@DienThoai"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HinhAnh", SqlDbType.NVarChar);
            cmd.Parameters["@HinhAnh"].Value = obj.HinhAnh.ToString();
            cmd.Parameters["@HinhAnh"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HuongNghienCuu", SqlDbType.NVarChar);
            cmd.Parameters["@HuongNghienCuu"].Value = obj.HuongNghienCuu.ToString();
            cmd.Parameters["@HuongNghienCuu"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@NoiCongTac", SqlDbType.NVarChar);
            cmd.Parameters["@NoiCongTac"].Value = obj.NoiCongTac.ToString();
            cmd.Parameters["@NoiCongTac"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@MaBoMon", SqlDbType.Int);
            cmd.Parameters["@MaBoMon"].Value = obj.MaBoMon;
            cmd.Parameters["@MaBoMon"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();

        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
}
